<?php

/**
 * Created by PhpStorm.
 * User: admin
 * Date: 2016/3/25
 * Time: 18:58
 */
class Model_PrizeRecord extends PhalApi_Model_NotORM{
  protected function getTableName($id){
    return 't_prizerecord';    //用户购买商户的记录
  }

  /**
   * 获取今天相关奖品被中奖次数
   */
  public function getTodayPrize($prizeId){
    return $this->getORM()->select('count(*) count')
      ->where('prizeId',$prizeId)
      ->where('createtime<?',strtotime(date("Y-m-d",strtotime("+1 day"))))
      ->where('createtime>=?',strtotime(date("Y-m-d")))
      ->fetchOne();
  }

  /**
   *插入中奖纪录
   */
  public function InsertPrizedRecord($userid,$prizeId){
    $this->getORM()->insert(array('userid'=>$userid,'prizeId'=>$prizeId,'createtime'=>time()));
  }
}